﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;

namespace FMS.Formulation.Licensing.Engine
{

    internal class WMIProcessorInfo
    {
        private const string WIN32_PROCESSOR = "Win32_Processor";

        private const string DESCRIPTION = "Description";

        private const string DEVICEID = "DeviceID";

        private const string NAME = "Name";

        private const string PROCESSORID = "ProcessorID";

        private int _id = 0;

        private string procDescription = string.Empty;

        private string deviceID = string.Empty;

        private string procName = string.Empty;

        private string procID = string.Empty;

        public int ID => _id;

        public string ProcessorName
        {
            get
            {
                return procName;
            }
            internal set
            {
                procName = value;
            }
        }

        public string ProcessorDescription => procDescription;

        public string DeviceID
        {
            get
            {
                return deviceID;
            }
            internal set
            {
                deviceID = value;
            }
        }

        public string ProcessorID => procID;

        public void Read()
        {
            WqlObjectQuery query = new WqlObjectQuery("SELECT Name, ProcessorID FROM Win32_Processor WHERE DeviceID='CPU0'");
            ManagementScope scope = new ManagementScope("\\root\\cimv2");
            ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(scope, query);
            try
            {
                ManagementObjectCollection managementObjectCollection = managementObjectSearcher.Get();
                foreach (ManagementObject item in managementObjectCollection)
                {
                    procName = item.GetPropertyValue("Name").ToString().Trim();
                    deviceID = item.GetPropertyValue("ProcessorID").ToString().Trim();
                }
            }
            catch
            {
            }
        }
    }

}
